/*绑定回车到查询按钮*/
$(function(){
	$(document).keydown(function(){ 
		if(event.keyCode==13){ 
		$(".obtn1").trigger('click'); 
		return false;
		}
	});
});
var qianfeijlid="";
var huanzheid='';
var gxjinyongflag=null;
//**列表勾销按钮**
$('#qfjl-gxqueding').on('click',function(){
	var id =qianfeijlid;
	var qianming=$('#qfjl-gxqianming').val();
	if(gxjinyongflag!=1||id==''||!qianming)return;
	$('#qfjl-gxqueding').attr('disabled',true);
	gxjinyongflag=2;
		$.ajax({
		//请求方式为get
		type:"POST",
		//获取json文件路径
		url:"../chaxuntjqfjl/gouXiaoqf",
		//传送数据
		data:{id:id,
			qianming:qianming},
		//请求成功完成后要执行的方法
		success:function(data){	
			if(data=='true'){
				$("#goux").modal('hide');
				notifySuccess("勾销记录成功！");
				getQianfejl();
			}else{
				gxjinyongflag=1;
				$('#qfjl-gxqueding').attr('disabled',false);
			}
		 }
	});
});

 //下拉匡取值
$("#ul-zhuangtai li").click(function(){
	var bText = $(this).text();
    var bValue = $(this).val();
    $(this).parent().siblings("#div-zhuangtai").html(bText+"<b></b>");
    $(this).parent().siblings("#qfjl-zhuangt").val(bValue);
    $(this).parent().css("display","none");
    //状态改变进行查询
    xingmingsj = $("#chaxxingming").val();
    kaishisj = $('#qfjl-kaishjsj').val();
    jieshusj = $('#qfjl-jieshusj').val();
    pageNumber= 1;
    zhuangtai=  bValue;
    dwpanduan= false;
    getQianfejl();
});

//查询按钮
 $("#chaxtj-qf-chaxunanniu").click(function(){
     xingmingsj = $("#chaxxingming").val();
     kaishisj = $('#qfjl-kaishjsj').val();
     jieshusj = $('#qfjl-jieshusj').val();
     zhuangtai= $('#qfjl-zhuangt').val();
     pageNumber= 1;
     dwpanduan= false;
     getQianfejl();
    });
//传递初始时间
function getShijian(prekaishisj,prejieshusj){
//	查询条件重置按钮
	$("#chaxtj-qf-chongzhi").click(function(){
	$("#chaxxingming").val("");
	$('#qfjl-kaishjsj').val(prekaishisj);
	$('#qfjl-jieshusj').val(prejieshusj);
	$('#qfjl-zhuangt').val(1);
	$('#div-zhuangtai').text('未补费').append('<b></b>');
//	查询条件进行重置后进行查询(增加判断防止未取到值)
	if(prekaishisj!=null){
		xingmingsj='';
		kaishisj=prekaishisj;
		jieshusj=prejieshusj;
		zhuangtai=1;
		pageNumber=1;
		dwpanduan=false;
		getQianfejl();
	}
});
	//页面正常显示
	if(prekaishisj!=null||dwkaishisj!='null'){
		if(dwxingmingsj!=''&&dwxingmingsj!='null'){
			xingmingsj=dwxingmingsj;
			$("#chaxxingming").val(dwxingmingsj);
		}else {
			xingmingsj='';
		}
		if(dwkaishisj!=''&&dwkaishisj!='null'){
			kaishisj=dwkaishisj;
			jieshusj=dwjieshusj;
			$('#qfjl-kaishjsj').val(kaishisj);
			$('#qfjl-jieshusj').val(jieshusj);
		}else{
			kaishisj=prekaishisj;
			jieshusj=prejieshusj;
		}
		if(zhuangtai!=null&&zhuangtai!='null'){
			zhuangtai=zhuangtai;
			if(zhuangtai==0){
				$('#qfjl-zhuangt').val(0);
				$('#div-zhuangtai').html('已补费'+"<b></b>");
			}else if(zhuangtai==1){
				$('#qfjl-zhuangt').val(1);
				$('#div-zhuangtai').html('未补费'+"<b></b>");
			}else if(zhuangtai==2){
				$('#qfjl-zhuangt').val(2);
				$('#div-zhuangtai').html('全部'+"<b></b>");
			}
		}else{
			zhuangtai=1;
		}
		getQianfejl();
	}
}


var kaishisj ='';
var jieshusj = '';
var xingmingsj = '';
var zhuangtai=1;
//定位用参数和传值函数
var pageNumber=1;
var qfdingweiid='';
var dingwei='';
var dwpanduan=true;
var dwkaishisj='';
var dwjieshusj='';
var dwxingmingsj='';
function qfdingwei(preqianfeiid,prepageNo,prezhuangtai,prekaishisj,prejieshusj,prexingmingsj){
	if(prepageNo!='null'&&preqianfeiid!='null'){
		qfdingweiid=preqianfeiid;
		pageNumber=prepageNo;
		zhuangtai=prezhuangtai;
		dwkaishisj=prekaishisj;
		dwjieshusj=prejieshusj;
		dwxingmingsj=prexingmingsj;
	}
}
//勾销按钮
$(document).on("click",".obtn8",function(){
 		$("#goux").modal();
});
//欠费
function getQianfejl(){
	 var totalNumber = 0;
	 var params={
		kaishisj:kaishisj,
		jieshusj:jieshusj,
		xingmingsj:xingmingsj,
		zhuangtai:zhuangtai
    			};
    $.ajax({
        //请求方式为get
        type:"get",
        //获取json文件路径
        url:"../chaxuntjqfjl/getCount",
        data:params,
    	async:false,
        //请求成功完成后要执行的方法
        success: function(data){
	    	totalNumber = data;
	    	if(totalNumber==0){
				$("#chaxtjqfjl-tbneirong").css("display","none");
				$("#cxtj-qf-img").html("<img src='"+path+"/image/chaxtj/cxtj-nobody.png'>");
			}else{
				$("#chaxtjqfjl-tbneirong").css("display","block");
				$("#cxtj-qf-img").html("");
			}
    	}
    });
    
    function createDemo(name) {
    	$('#tbqianfeijl').html('');
		var container = $('#pagination-'+name);
		container.pagination({
		dataSource:'../chaxuntjqfjl/getBypage?kaishisj='+encodeURI(kaishisj)+'&jieshusj='+encodeURI(jieshusj)+'&xingmingsj='+encodeURI(xingmingsj)+'&zhuangtai='+encodeURI(zhuangtai),
		locator: 'entities',
		pageSize: 12,
		pageNumber:pageNumber,
		showNavigator: true,
   	    formatNavigator: '共 <%= totalNumber %> 条',
		totalNumber: totalNumber,
		callback: function(data, pagination){
			//定位姓名手机局部变量
			    dwxingmingsj =$("#chaxxingming").val();
    			var content = '';
    			$(data).each(function(index,value){
    				if(this.zhuangtai==0){
    				var zhuangtaitext="已补费";
    			}else{
    				var zhuangtaitext="未补费";
    			}
    			if(this.nianling==null){
    					var nianling="";
    			}else if(this.nianlingdw==null){
    					var nianling=this.nianling;
    				}else{
    					var nianling=this.nianling+this.nianlingdw;
    				}
    			if(this.xingbie==1){
    					var sex="男";
    				}else if(this.xingbie==2){
    					var sex ="女";
    				}else{
    					var sex="";
    				}
    				var shifuje=parseFloat(this.shishouje).toFixed(2);
    				var index=((pagination.pageNumber-1)*pagination.pageSize)+index+1;
    				content += '<tr class="user" id="qfhang'+index+'">'+
    				'<td width="10%">'+index+'</td>'+
    				'<td width="10%" class="left"><span class="icon-user" onclick=getHuanzhe('+this.huanzheid+')></span>'+this.xingming+'</td>'+
    				'<td width="7%">'+sex+'</td>'+
    				'<td width="10%">'+nianling+'</td>'+
    				'<td width="10%">'+this.jianfeisj+'</td>'+
    				'<td width="10%">'+zhuangtaitext+'</td>'+
    				'<td width="9%" class="right">'+parseFloat(this.zhehouje).toFixed(2)+'</td>'+
    				'<td width="9%" class="right">'+shifuje+'</td>'+
    				'<td width="9%" class="right">'+parseFloat(this.jine).toFixed(2)+'</td>'+
    				'<td width="16%">'+
    				'<div class="table-operation">'+
    				'<span class="obtn3" id="'+this.id+'" onclick="qfjlxq('+this.id+','+pagination.pageNumber+','+zhuangtai+',\''+dwxingmingsj+'\')">详情</span>';
    				if(this.huankuanjlid==null) {
    				content +='<span class="obtn4" huankuan="'+this.huanzheid+'" onclick="qfjlhkxq('+this.huanzheid+','+pagination.pageNumber+','+this.id+','+zhuangtai+',\''+dwxingmingsj+'\')">还款</span>'+
    				'<span class="obtn8" id="'+this.id+'" onclick="gouxiao('+this.id+')">勾销</span>';
    				}
    				content +='</div></td></tr>';
    				//查询状态定位判断Fjh
					if(qfdingweiid==this.id){
						dingwei=index;
	        		}
    			});
    			$('#tbqianfeijl').html(content);
    			//查询状态定位Fjh
	        	if(dingwei!=null&&dingwei!=''){
	 	        	$('#tbqianfeijl').find('tr[id="qfhang'+dingwei+'"]').addClass('list-tr');
	        	}
				//点击查询按钮和重置按钮定位状态消失
	        	if(!dwpanduan){
	        		$('#tbqianfeijl').find('tr[id="qfhang'+dingwei+'"]').removeClass('list-tr');
	       	 	}
    		}
    });
		 return container;
	}
		createDemo('fenyqfjl');
		if(totalNumber <= 12) {
			$('#pagination-fenyqfjl').css('display','none');
		}else{
			$('#pagination-fenyqfjl').css('display','block');
		}
}
function gouxiao(id){
	 qianfeijlid=id;
	 gxjinyongflag=1;
	 $.ajax({
		url:path+'/base/getQianming',
		type:'POST',
		success:function(data) {  
			$('#qfjl-gxqianming').val(data);
		}
	});
}

//跳转进欠费记录详情
function qfjlxq(id,prepageNo,prezhuangtai,predwxingmingsj){
	var predwxingmingsj =encodeURI(encodeURI(predwxingmingsj));
	$('.cxtj-neirk').load(path+ "/views/chaxun-tongji/chaxtj-qianfjl-qianfxq.jsp?yemianrk=qianfeijl&ID="+id+"&pageNo="+prepageNo+"&zhuangtai="+prezhuangtai+"&kaishisj="+kaishisj+"&jieshusj="+jieshusj+"&dwxingmingsj="+predwxingmingsj);
}

//跳转进还款详情
function qfjlhkxq(huankuan,prepageNo,preqianfeiid,prezhuangtai,predwxingmingsj){
	var predwxingmingsj =encodeURI(encodeURI(predwxingmingsj));
	$('.cxtj-neirk').load(path+ "/views/chaxun-tongji/chaxtj-qianfjl-hkxq.jsp?yemianrk=qianfeijl&ID="+preqianfeiid+"&qianfeiid="+preqianfeiid+"&pageNo="+prepageNo+"&zhuangtai="+prezhuangtai+"&kaishisj="+kaishisj+"&jieshusj="+jieshusj+"&dwxingmingsj="+predwxingmingsj);
	$("#huankuan").css("border-bottom","none");
}

